﻿<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:graph="clr-namespace:zeal.ui.graph">
    <Style TargetType="{x:Type graph:GraphPort}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type graph:GraphPort}">
                    <ControlTemplate.Resources>
                        <Style x:Key="connectorDimensions" TargetType="{x:Type Ellipse}">
                            <Setter Property="Canvas.Left" Value="-9"/>
                            <Setter Property="Canvas.Top" Value="4"/>
                            <Setter Property="Width" Value="14"/>
                            <Setter Property="Height" Value="14"/>
                            <Setter Property="ClipToBounds" Value="False"/>
                        </Style>
                        <Style x:Key="canvasDimensions" TargetType="{x:Type Canvas}">
                            <Setter Property="Width" Value="7"/>
                            <Setter Property="Height" Value="20"/>
                            <Setter Property="ClipToBounds" Value="False"/>
                        </Style>
                    </ControlTemplate.Resources>
                    <StackPanel x:Name="PART_root" Height="20" Margin="0" HorizontalAlignment="Stretch" Orientation="Horizontal" Cursor="Arrow">
                        <Canvas ClipToBounds="False" Style="{StaticResource canvasDimensions}">
                            <Ellipse x:Name="PART_connector" Style="{StaticResource connectorDimensions}"  StrokeThickness="2" 
                             Stroke="{Binding PortBorder.Brush}" Fill="{Binding PortFill}"/>
                        </Canvas>
                        <DockPanel>
                            <TextBlock x:Name="PART_text" ClipToBounds="True"  Text="{Binding name}" Margin="0,0,4,0"
                                TextTrimming="CharacterEllipsis" Foreground="White" TextOptions.TextFormattingMode="Display">
                            </TextBlock>
                        </DockPanel>
                    </StackPanel>
                    <ControlTemplate.Triggers>

                        <!-- Input/output styling -->
                        <DataTrigger Binding="{Binding isInput}" Value="True">
                            <Setter TargetName="PART_root" Property="FlowDirection" Value="LeftToRight"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding isInput}" Value="False">
                            <Setter TargetName="PART_root" Property="FlowDirection" Value="RightToLeft"/>
                        </DataTrigger>

                        <!-- drag sate styling -->
                        <DataTrigger Binding="{Binding ConnectionState}" Value="ERROR">
                            <Setter TargetName="PART_text" Property="Foreground" Value="Red"/>
                            <Setter TargetName="PART_text" Property="TextDecorations" Value="Underline"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ConnectionState}" Value="VALID">
                            <Setter TargetName="PART_text" Property="TextDecorations" Value="Underline"/>
                        </DataTrigger>
                        
                        <!-- Underline -->
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="PART_text" Property="TextDecorations" Value="Underline"/>
                        </Trigger>
                        
                        <!-- optional -->
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsConnected}" Value="False"/>
                                <Condition Binding="{Binding isOptional}" Value="True"/>
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="PART_text" Property="FontStyle" Value="Italic"/>
                        </MultiDataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>